package com.anywhere.freightman.order.service.impl;

import com.anywhere.freightman.common.BaseMapper;
import com.anywhere.freightman.common.BaseService;
import com.anywhere.freightman.order.dao.GoodsDao;
import com.anywhere.freightman.order.model.GoodsModel;
import com.anywhere.freightman.order.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.weekend.Weekend;
import tk.mybatis.mapper.weekend.WeekendCriteria;

import java.util.List;

@Service
@Transactional
public class GoodService extends BaseService<GoodsModel> implements IGoodsService {

    @Autowired
    private GoodsDao goodsDao;

    @Override
    public BaseMapper<GoodsModel> getBaseDao() {
        return goodsDao;
    }

    @Override
    public Example getExample(GoodsModel entity) {
        Weekend<GoodsModel> weekend = Weekend.of(GoodsModel.class);
        WeekendCriteria<GoodsModel, Object> criteria = weekend.weekendCriteria();

        if (entity == null) {
            return weekend;
        }

        if (entity.getOrderNo() != null) {
            criteria.andEqualTo("orderNo", entity.getOrderNo());
        }

        return weekend;
    }

    @Override
    public List<GoodsModel> getListByOrderNo(String orderNo) {
        return goodsDao.getListByOrderNo(orderNo);
    }
}
